package Demo;

import java.util.Stack;

class MyQueue {
    //定义2个栈
    private Stack<Integer> s1;
    private Stack<Integer> s2;
    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    /**
     * 入的时候 统一放到s1当中
     * @param x
     */
    public void push(int x) {
        s1.push(x);
    }

    //出的时候 统一出s2的
    public int pop() {
        if( empty()) {
            return -1;
        }

        if(s2.empty()) {
            while (!s1.empty()) {
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int peek() {
        if( empty()) {
            return -1;
        }

        if(s2.empty()) {
            while (!s1.empty()) {
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.empty() && s2.empty();
    }
}